package com.example.teaching_server.controller;

import com.example.teaching_server.common.ApiResponse;
import com.example.teaching_server.dto.SidebarDTO;
import com.example.teaching_server.service.StudentSidebarService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/api/student/sidebar")
@RequiredArgsConstructor
@Tag(name = "学生侧边栏管理", description = "学生侧边栏数据查询接口")
public class StudentSidebarController {

    private final StudentSidebarService sidebarService;

    /**
     * 获取学生侧边栏数据
     */
    @GetMapping
    @Operation(summary = "获取学生侧边栏数据", description = "根据学生用户ID获取侧边栏相关数据")
    public ApiResponse<SidebarDTO> getSidebarData(
            @Parameter(description = "学生用户ID")
            @RequestParam Long userId) {

        log.info("开始获取学生侧边栏数据: userId={}", userId);

        try {
            SidebarDTO data = sidebarService.getSidebarData(userId);
            log.info("成功获取学生{}的侧边栏数据", userId);
            return ApiResponse.success("学生侧边栏数据获取成功", data);
        } catch (Exception e) {
            log.error("获取学生侧边栏数据失败: userId={}", userId, e);
            return ApiResponse.fail("获取学生侧边栏数据失败: " + e.getMessage());
        }
    }
}
